import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
class newsDetail extends StatefulWidget{
  final String url;
  final String title;
  const newsDetail({Key ? key, required this.url,required this.title})
   :super(key: key);
  @override
  newsDetailState createState()=> newsDetailState();
}

class newsDetailState extends State<newsDetail>{
  bool loaded = false;
  final flutterWebViewPlugin = FlutterWebviewPlugin();
  newsDetailState({Key? key});
  @override
  void initState(){
    super.initState();
    setState(() {
      flutterWebViewPlugin.onStateChanged.listen((state) {
        print("state:${state.type}");
        if(state.type == WebViewState.finishLoad){
          setState(() {
            loaded = true;
          });
        }
      });
    });
  }
  @override
  Widget build(BuildContext context) {
    List<Widget> titleContent = [];
    titleContent.add(Text(
      widget.title,
      overflow: TextOverflow.ellipsis,
      style: TextStyle(
        fontSize: 13.0
      ),
    ));
    if(!loaded){
      titleContent.add(CupertinoActivityIndicator());
    }
    titleContent.add(Container(width: 50.0,));
    return WebviewScaffold(url: widget.url,
    appBar: AppBar(
      title: Expanded(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: titleContent,
        ),
      ),
    ),
      withZoom: false,
      withJavascript: true,
      withLocalStorage: true,
    );
  }
}